﻿(function ($) {
    app.modals.CreateOrEditBillAccountModal = function () {

        var _dataMaintainService = abp.services.app.dataMaintain;
        var _modalManager;
        var _$form = null;

        this.init = function (modalManager) {
            _modalManager = modalManager;

            _$form = _modalManager.getModal().find('form[name=ObjectForm]');
            _$form.validate();
        };

        this.save = function () {
            if (!_$form.valid()) {
                return;
            }

            var domainObject = _$form.serializeFormToObject();
   
            _modalManager.setBusy(true);
            _dataMaintainService.createOrUpdateBillAccount({
                //billAccount这个地方名称必须用Dto里面文件名称，不能用AppSerice前缀，否则一直提示参数不对，不能为空
                billAccount: domainObject   
            }).done(function (result) {
                abp.notify.info(app.localize('SavedSuccessfully'));
                _modalManager.setResult(result);
                _modalManager.close();
                abp.event.trigger('app.CreateOrEditModalSaved', result);
            }).always(function () {
                _modalManager.setBusy(false);
            });
        };
        //$("#AccountType").val($("#AccountTypeId").find("option:selected").text())

        $("#SchoolId").change(function () {
            $("#SchoolName").val($("#SchoolId").find("option:selected").text())
        });
        
        $("#AccountTypeId").change(function () {
            $("#AccountType").val($("#AccountTypeId").find("option:selected").text())
           
        });
    };
})(jQuery);